import pandas as pd
import os
from datetime import datetime


def dehydration(df):
    rename_dict = {}
    for n, w in enumerate([10, 20, 40, 80, 160]):
        rename_dict[f"qr_{w}"] = f"q_{n}"

    for n, window in enumerate([6, 12, 24, 48, 96]):
        rename_dict[f"ma_deviation_{window}"] = f"m_{n}"
        rename_dict[f"atr_{window}"] = f"a_{n}"
    rename_dict["volume1"] = "v1"
    rename_dict["volume2"] = "v2"
    rename_dict["position_1"] = "p1"
    rename_dict["position_5"] = "p2"
    rename_dict["position_30"] = "p3"

    rename_dict["time_since_open"] = "t1"
    rename_dict["time_to_close"] = "t2"

    for n, w in enumerate([3, 6, 15]):
        rename_dict[f"support_{w}"] = f"ss_{n}"
        rename_dict[f"pressure_{w}"] = f"pp_{n}"

    df.rename(rename_dict, inplace=True, axis=1)

    dt = datetime(2023, 6, 1)
    df = df[:dt]
    return df


if __name__ == "__main__":
    factor_data_path = "D:\daily work\ml\\raw"

    files = os.listdir(factor_data_path)

    dfs = []

    for file_name in files:
        if "dehydration" in file_name:
            continue
        print(file_name)
        df = pd.read_csv(f"{factor_data_path}\\{file_name}")
        df["datetime"] = pd.to_datetime(df["datetime"])
        df.set_index("datetime", inplace=True)

        #df = dehydration(df)

        dt = datetime(2023, 6, 1)

        df = df[:dt]
        dfs.append(df)

